//
//  PushHot.m
//  HYHOME
//
//  Created by cjy on 16/2/28.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "PushHot.h"
#import "PushHotCell.h"
#import "NetHandleBlock.h"
#import "UIImageView+WebCache.h"
#import "TitleTableViewCell.h"
#import "DescriptionTableViewCell.h"
#import "BuyViewController.h"
#import "HotModel.h"

#import "DKNightVersion.h"
@interface PushHot ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UITableView *tableView;

@property (nonatomic,retain)NSString *str;
@property (nonatomic,retain)UIImageView *asd;
@end

@implementation PushHot

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    
    
    [self createtableView];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fenxiang"] style:UIBarButtonItemStylePlain target:self action:@selector(buy)];
    
}


- (void)buy{

    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"" preferredStyle: UIAlertControllerStyleActionSheet];
    
    UIAlertAction *actionOk =[UIAlertAction actionWithTitle:@"去购买" style:0 handler:^(UIAlertAction * _Nonnull action) {
       

        BuyViewController *buy = [[BuyViewController alloc]init];
        
       
        
    
        buy.buyLink = self.buylink ;

        if (buy.buyLink == nil) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"无购买链接" preferredStyle: UIAlertControllerStyleAlert];
            
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alert addAction:action];
            
            
            [self presentViewController:alert animated:YES completion:^{
                
            }];

        }
        
        
        
        [self.navigationController pushViewController:buy animated:YES];
        
        

    
    }];
    
    UIAlertAction *actioncancel = [UIAlertAction actionWithTitle:@"取消" style:1 handler:^(UIAlertAction * _Nonnull action) {
       
        
    }];
    
    [alert addAction:actioncancel];
    [alert addAction:actionOk];
    
    [self presentViewController:alert animated:YES completion:nil];
    

}

- (void)createtableView{

    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerClass:[TitleTableViewCell class] forCellReuseIdentifier:@"pool2"];
    [self.tableView registerClass:[PushHotCell class] forCellReuseIdentifier:@"pool"];
    [self.tableView registerClass:[DescriptionTableViewCell class] forCellReuseIdentifier:@"pool3"];
    
    
    self.tableView.dk_backgroundColorPicker =  DKColorWithRGB(0xffffff, 0x343434);
    self.tableView.dk_separatorColorPicker = DKColorWithRGB(0xaaaaaa, 0x313131);
    

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
   
        return self.arrrr.count +2;
        
    
    
        
  


}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    PushHotCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    TitleTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:@"pool2"];
    DescriptionTableViewCell *cell3 = [tableView dequeueReusableCellWithIdentifier:@"pool3"];
    
    cell.selectionStyle = UITableViewCellAccessoryNone;

    if (indexPath.row == 0) {
        
        [cell2 passModel:self.title2];
        cell2.selectionStyle = UITableViewCellAccessoryNone;

        
         return cell2;

    }else if (indexPath.row == 1){
    
        cell3.selectionStyle = UITableViewCellAccessoryNone;

        [cell3 passModel:self.des];
        return cell3;
    
    
    
    } else {
       

       
        [cell passModel:[self.arrrr[indexPath.row - 2] objectForKey:@"pic"]];

            return cell;
       
    }

 
    

    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row==0) {
        
        return 50;
    }else if(indexPath.row == 1){
    
    
    return [DescriptionTableViewCell heightForCell:self.des];
//        return 100;
    
    } else {
    
         return 200;
        
    }


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
